package com.pagoda.nerp.trade.common.wx.handler;

import com.pagoda.nerp.trade.common.objectutil.ThreadPoolSingleton;
import com.pagoda.nerp.trade.common.wx.module.WxTemplateMsgBuilder;
import com.pagoda.nerp.trade.common.wx.thread.WxMessagePushJob;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 处理并发送微信魔板消息
 *
 * Created by Jungle on 2016/12/21.
 */
public class WxMessageHandler {

    private static Logger logger = LoggerFactory.getLogger(WxMessageHandler.class);

    private WxMessageHandler() {
    }

    /**
     * 发送注册审核通知
     * @param first 抬头，可为空喘
     * @param userName 账户名
     * @param phoneNumber 手机号
     * @param datetime 时间 yyyy-MM-dd HH:mm:ss
     * @param content remark备注内容
     * @param toUser 接收者
     */
    public static void sendRegisterNotifyMsg(String first,String userName,String phoneNumber,String datetime,String content,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", userName);
        params.put("keyword2", phoneNumber);
        params.put("keyword3", datetime);
        if(StringUtils.isNotEmpty(content)){
            params.put("remark", content);
        }else{
            params.put("remark", WxTemplateMsgBuilder.CONSTAT_REMART);
        }
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_REGISTER_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

    /**
     * 发送信息发布通知模板消息
     * @param first 抬头
     * @param publish 发布信息：eg -> 百果园 --发布方
     * @param content 发布内容
     * @param datetime 发布时间
     * @param remark 备注：如有疑问请致电4001811212
     * @param toUser 接收者
     */
    public static void sendInfoPublishNotifyMsg(String first,String publish,String content,String datetime,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", publish);
        params.put("keyword2", content);
        params.put("keyword3", datetime);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_INFO_PUBLISH_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

    /**
     * 发送质检问题提醒
     * @param first 抬头信息，可为空
     * @param qualityUser 质检员
     * @param vendor 供应商名称
     * @param datetime 时间
     * @param remark 备注
     * @param toUser 接收者
     */
    public static void sendQualityPublishNotifyMsg(String first,String qualityUser,String vendor,String datetime,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", qualityUser);
        params.put("keyword2", vendor);
        params.put("keyword3", datetime);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_QUALITY_PUBLICSH_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

    /**
     * 发送中标模板消息通知
     * @param first 抬头，可不填
     * @param goodsName 商品名称
     * @param datetime 时间
     * @param remark 备注
     * @param toUser 接收方
     */
    public static void sendBidNotifyMsg(String first,String goodsName,String datetime,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", goodsName);
        params.put("keyword2", datetime);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_BID_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

    /**
     * 发送《新采购提醒》通知
     * @param first 抬头信息
     * @param purTitle 采购标题
     * @param purCount 采购数量
     * @param buyVendorName 买家昵称
     * @param datetime 发布时间
     * @param remark 附加备注信息
     * @param toUser 通知接收人
     */
    public static void sendNewPurchaseNotify(String first,String purTitle,String purCount,String buyVendorName,String datetime,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", purTitle);
        params.put("keyword2", purCount);
        params.put("keyword3",buyVendorName);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_NEW_PURCHASE_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

    /**
     * 发送《收到报价通知》模板消息
     * @param first 抬头，根据内容自定义
     * @param offerDate 报价时间
     * @param offerMarker 报价人
     * @param offerProduct 报价产品
     * @param offerDetail 报价详情
     * @param remark 附加备注
     * @param toUser 消息接收人
     */
    public static void sendReceiveOfferNotify(String first,String offerDate,String offerMarker,String offerProduct,String offerDetail,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", offerDate);
        params.put("keyword2", offerMarker);
        params.put("keyword3",offerProduct);
        params.put("keyword4",offerDetail);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_RECEIVE_OFFER_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

    /**
     * 发送《新询价单通知》模板消息
     * @param first 抬头
     * @param inquiryUnit 询价单位
     * @param inquiryTime 询价时间
     * @param productName 产品名称
     * @param count 产品数量
     * @param remark 附加备注
     * @param toUser 发送者
     */
    public static void sendNewInquiryNotify(String first,String inquiryUnit,String inquiryTime ,String productName,String count,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", inquiryUnit);
        params.put("keyword2", inquiryTime);
        params.put("keyword3",productName);
        params.put("keyword4",count);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_NEW_INQUIRE_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }


    /**
     * 发送《质检申请发布通知》模板消息
     * @param first 抬头
     * @param buySquare 需求方
     * @param applyTime 申请时间
     * @param remark 附加配置
     * @param toUser 接收人
     */
    public static void sendApplyPurchasePublishNotify(String first,String buySquare,String applyTime,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", buySquare);
        params.put("keyword2", applyTime);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_APPLY_PURCHASE_PUBLISH_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

    /**
     * 发布《质检需求反馈通知》模板消息
     * @param first 抬头
     * @param purSequare 质检方
     * @param publishTime 发布时间
     * @param remark 附加备注信息
     * @param toUser 接受者
     */
    public static void sendDemandFeedbackNotify(String first,String purSequare,String publishTime,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", purSequare);
        params.put("keyword2", publishTime);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_DEMAND_FEEDBACK_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

    /**
     * 发送《报告生成通知》模板消息
     * @param first 抬头
     * @param reportPro 检测水果
     * @param reportNo 质检单编号
     * @param reportTime 生成日期
     * @param remark 附加备注
     * @param toUser 接收者
     */
    public static void sendReportGeneratorNotify(String first,String reportPro,String reportNo,String reportTime,String remark,String toUser){
        Map params = new HashMap();
        params.put("first", first);
        params.put("keyword1", reportPro);
        params.put("keyword2", reportNo);
        params.put("keyword3",reportTime);
        params.put("remark", remark);
        Map<String,Object> dataMap = WxTemplateMsgBuilder.buildNotifytTpl(params);
        Runnable command = new WxMessagePushJob(dataMap, "", toUser, WxTemplateMsgBuilder.WX_TEMPLATE_REPORT_GENERATOR_NOTIFY);
        ThreadPoolSingleton.execute(command);
    }

}
